<#include "./custom.include">
<#assign className = table.className>
<#assign classNameFirstLower = className?uncap_first>
<#assign classNameLowerCase = className?lower_case>
<#assign pkJavaType = table.pkColumn.simpleJavaType>
package ${basepackage}.controller;

import lombok.RequiredArgsConstructor;
import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;
import org.springframework.web.bind.annotation.*;
<#include "./java_imports.include">

@RestController
@RequestMapping("${classNameLowerCase}")
@RequiredArgsConstructor
public class ${className}Controller extends BaseSpringController {
	protected static final String DEFAULT_SORT_COLUMNS = "id DESC"; // 默认排序, eg: username DESC,create_at ASC

	private final ${className}Service ${classNameFirstLower}Service;

	/** 列表 */
	@GetMapping
	public Page<${className}> list(@RequestParam Map<String, Object> params, HttpServletRequest request) {
		PageRequest pageRequest = pageRequest(request, DEFAULT_SORT_COLUMNS);
		Page<${className}> page = ${classNameFirstLower}Service.findByPageRequest(pageRequest);
		return page;
	}

	/** 详情 */
	@GetMapping("{id}")
	public ${className} get(@PathVariable ${pkJavaType} id) {
		${className} ${classNameFirstLower} = ${classNameFirstLower}Service.getById(id);
		return ${classNameFirstLower};
	}

	/** 新增 */
	@PostMapping
	public ${pkJavaType} create(@Valid ${className} ${classNameFirstLower}) {
		${classNameFirstLower}Service.save(${classNameFirstLower});
		return ${classNameFirstLower}.getId();
	}

	/** 更新 */
	@PutMapping("{id}")
	public void update(@PathVariable ${pkJavaType} id, @Valid ${className} ${classNameFirstLower}) {
		${classNameFirstLower}Service.update(${classNameFirstLower});
	}

	/** 删除 */
	@DeleteMapping("{id}")
	public void delete(@PathVariable ${pkJavaType} id) {
		${classNameFirstLower}Service.deleteById(id);
	}

	/** 批量删除 */
	public void deleteBatch(@RequestParam List<${pkJavaType}> items) {
		${classNameFirstLower}Service.deleteBatch(items);
	}

}